package com.fattyCorps.controller;


import com.fattyCorps.obj.msg.SRet;
import com.fattyCorps.obj.msg.client.login.CLoginMsg;
import com.fattyCorps.obj.msg.client.login.CRegMsg;
import com.fattyCorps.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
//@RequestMapping("/login")
public class LoginController {

    @Autowired
    LoginService loginService;

    // 注册
    @PostMapping("/reg")
    public SRet reg(@RequestBody CRegMsg cRegMsg){
        // 调用LoginService中的reg方法
//        返回值SRegMsg = loginService.reg(账号，密码);
        SRet reg = loginService.reg(cRegMsg.getAccount(), cRegMsg.getPassword());
        return reg;
    }

    // 登录
    @PostMapping("/login")
    public SRet login(@RequestBody CLoginMsg cLoginMsg){
        // 调用LoginService中的login方法
        SRet login = loginService.login(cLoginMsg.getAccount(), cLoginMsg.getPassword());
        return login;
    }
}